package com.seecen.controller;

import com.seecen.entity.BookCategory;
import com.seecen.service.BookCategoryService;
import com.seecen.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bookCategory")
public class BookCategoryController {

    @Autowired
    private BookCategoryService bookCategoryService;


    @PostMapping("/save")
    public Result<BookCategory> saveBookCategory(@RequestBody BookCategory bookCategory) {
        bookCategoryService.save(bookCategory);
        return Result.success();
    }

    @PostMapping("/saveCateGoryAndBook")
    public Result<BookCategory> saveCateGoryAndBook(@RequestBody BookCategory bookCategory) {
        bookCategoryService.saveCateGoryAndBook(bookCategory);
        return Result.success();
    }



    @DeleteMapping("/delete/{id}")
    public Result<BookCategory> deleteBookCategory(@PathVariable int id) {
        Result result = bookCategoryService.deleteById(id);
        return result;
    }

    @PutMapping("/update")
    public Result<BookCategory> updateBookCategory(@RequestBody BookCategory bookCategory) {
        bookCategoryService.update(bookCategory);
        return Result.success();
    }

    @GetMapping("/get")
    public Result<List<BookCategory>> getBookCategory(@RequestBody(required = false) BookCategory bookCategory) {
        List<BookCategory> list = bookCategoryService.findByParam(bookCategory);
        return Result.success(list);
    }
}
